/*******************************************************************************
 * Copyright (c) 2011 Olexandr V. Shaposhnikov.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *    Olexandr V. Shaposhnikov - initial API and implementation and/or initial documentation
 *******************************************************************************/
package com.funkyroach.use.ui.wizard;

import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Path;
import org.eclipse.dltk.core.DLTKCore;
import org.eclipse.dltk.core.DLTKLanguageManager;
import org.eclipse.dltk.core.IDLTKLanguageToolkit;
import org.eclipse.dltk.core.IScriptLanguageProvider;
import org.eclipse.dltk.ui.util.IStatusChangeListener;
import org.eclipse.dltk.ui.wizards.BuildpathsBlock;
import org.eclipse.dltk.ui.wizards.ProjectWizardSecondPage;
import org.eclipse.dltk.utils.ResourceUtil;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;

import com.funkyroach.use.core.language.USNature;

public class USNewProjectWizardSecondPage extends ProjectWizardSecondPage {

    private BuildpathsBlock fBuildPathsBlock;
    private USUDKOptionsGroup fUDKOptions;

    /**
     * Create the wizard.
     */
    public USNewProjectWizardSecondPage() {
        super(null);
        setTitle("");
        setDescription("");
    }

    /**
     * Create contents of the wizard.
     * 
     * @param parent
     */
    public void createControl(Composite parent) {
        Composite container = new Composite(parent, SWT.NULL);
        setControl(container);
        container.setLayout(new GridLayout(2, false));
        fUDKOptions = new USUDKOptionsGroup(container, SWT.NULL);
    }

    private class BuildpathBlockListener implements IStatusChangeListener, IScriptLanguageProvider {

        public void statusChanged(IStatus status) {
            updateStatus(status);
        }

        public IDLTKLanguageToolkit getLanguageToolkit() {
            return DLTKLanguageManager.getLanguageToolkit(USNature.NATURE_ID);
        }
    }

    protected BuildpathsBlock getBuildPathsBlock() {
        if (fBuildPathsBlock == null) {
            fBuildPathsBlock = createBuildpathBlock(new BuildpathBlockListener());
        }
        return fBuildPathsBlock;
    }

    protected void configureNatures(IProject project, IProgressMonitor monitor) throws CoreException {
        ResourceUtil.addNature(project, monitor, USNature.NATURE_ID);
    }

    @Override
    protected void configureProject(IProject project, IProgressMonitor monitor) throws CoreException {
//        USNewProjectWizardFirstPage firstPage = (USNewProjectWizardFirstPage) getWizard().getPages()[0];
//        String udkHome = firstPage.getUDKHome();
//        IPath path = new Path(udkHome + "\\Development\\Source");
//
//        fBuildPathsBlock.addElement(DLTKCore.newSourceEntry(path));
        fBuildPathsBlock.configureScriptProject(monitor);
    }
}
